package com.google.gwt.sample.dynatablerf.server.util;


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BeanUtil {

	private static ApplicationContext getApplicationContext() {
		return new ClassPathXmlApplicationContext("/META-INF/applicationContext.xml");
	}
	
	public static <T> T getInstance(Class<T> clazz) {
		ApplicationContext applicationContext = getApplicationContext();
		return (T) applicationContext.getBean(clazz);
	} 
	
	@SuppressWarnings("unchecked")
	public static <T> T getInstance(String beanName) {
		ApplicationContext applicationContext = getApplicationContext();
		return (T) applicationContext.getBean(beanName);
	}
}
